package com.thiege.mall.common.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;


import java.io.Serializable;


/**
 * 服务响应对象
 * Created by wang on 2017/5/31.
 */
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class ServerResponse<T> implements Serializable {
    private boolean result;
    private T data;
    private String essage;

    public boolean isResult() {
        return result;
    }

    public T getData() {
        return data;
    }

    private String getEssage() {
        return essage;
    }

    private ServerResponse(boolean result) {
        this.result = result;
    }

    private ServerResponse(boolean result, T data) {
        this.result = result;
        this.data = data;
    }

    private ServerResponse(boolean result, String essage) {
        this.result = result;
        this.essage = essage;
    }

    private ServerResponse(boolean result, T data, String essage) {
        this.result = result;
        this.data = data;
        this.essage = essage;
    }

    /**
     *忽略
     * @return responseResult
     */
    @JsonIgnore
    public boolean isSuccess() {
        return result;
    }

    public static <T> ServerResponse<T> newInstanceOfSuccess() {
        return new ServerResponse<T>(true);
    }

    public static <T> ServerResponse<T> newInstanceOfFailure() {
        return new ServerResponse<T>(false);
    }

    public static <T> ServerResponse<T> newInstanceOfSuccess(String responseMessage) {
        return new ServerResponse<T>(true, responseMessage);
    }

    public static <T> ServerResponse<T> newInstanceOfFailure(String responseMessage) {
        return new ServerResponse<T>(false, responseMessage);
    }

    public static <T> ServerResponse<T> newInstanceOfSuccess(T data) {
        return new ServerResponse<T>(true, data);
    }

    public static <T> ServerResponse<T> newInstanceOfFailure(T data) {
        return new ServerResponse<T>(false, data);
    }

    public static <T> ServerResponse<T> newInstanceOfSuccess(T data, String responseMessage) {
        return new ServerResponse<T>(true, data, responseMessage);
    }

    public static <T> ServerResponse<T> newInstanceOfFailure(T data, String responseMessage) {
        return new ServerResponse<T>(false, data, responseMessage);
    }
}
